package com.demo.task;

import com.demo.model.ScheduleTask;
import com.demo.utils.SpringUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;

import java.lang.reflect.Method;

public class QuartzFactory implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext)  {
        //获取调度数据
        ScheduleTask scheduleJob = (ScheduleTask) jobExecutionContext.getMergedJobDataMap().get("scheduleJob");
        //获取对应的Bean
        Object object = SpringUtil.getBean(scheduleJob.getSpring_id());
        try {
            //利用反射执行对应方法
            Method method = object.getClass().getMethod(scheduleJob.getMethod_name());
            method.invoke(object);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
